# -*- coding: utf-8 -*-
"""
    Data: 2022/6/14
    Time: 16:05
    Author: Driving
"""
from login_page import LoginPage
from register_page import RegisterPage
from main_page import MainPage
from PyQt5.Qt import *
import sys


class Application:
    pass


if __name__ == '__main__':
    app = QApplication(sys.argv)
    login_page = LoginPage()
    register_page = RegisterPage(login_page)
    register_page.move(0, register_page.height())
    register_page.show()
    # em = QErrorMessage(login_page)
    # em.setWindowTitle("错误提示")
    main_page = MainPage()

    def exit_register_page():
        animation = QPropertyAnimation(register_page)
        animation.setTargetObject(register_page)
        animation.setPropertyName(b"pos")
        animation.setStartValue(QPoint(0, 0))
        animation.setEndValue(QPoint(0, register_page.height()))
        animation.setDuration(300)
        animation.setEasingCurve(QEasingCurve.InSine)
        animation.start(QAbstractAnimation.DeleteWhenStopped)

    def show_register_page():  # 可封装为工具类
        animation = QPropertyAnimation(register_page)
        animation.setTargetObject(register_page)
        animation.setPropertyName(b"pos")
        animation.setStartValue(register_page.pos())
        animation.setEndValue(QPoint(0, 0))
        animation.setDuration(300)
        animation.setEasingCurve(QEasingCurve.OutSine)
        animation.start(QAbstractAnimation.DeleteWhenStopped)

    def check_user_imformation(account, pw):
        if account == "admin":
            if pw == "123456":
                login_page.close()
                main_page.show()
        else:
            QMessageBox.about(login_page, "账户信息错误", "账户或密码错误")


    register_page.exit_signal.connect(exit_register_page)
    register_page.register_signal.connect(lambda account, pw: print(account, pw))
    login_page.show_register_signal.connect(show_register_page)
    login_page.check_login_signal.connect(lambda account, pw: check_user_imformation(account, pw))

    login_page.show()
    sys.exit(app.exec_())
